package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.domain.ApiAjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.enums.StatusEnum;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizHospitalFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizHospitalQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizHospitalVO;
import cn.sfrog.project.biz.admin.service.IBizHospitalService;
import cn.sfrog.project.biz.web.vo.order.AppServiceHospitalResultVO;
import cn.sfrog.project.biz.web.vo.service.AppServiceDetailQueryVO;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "管理后台-医院相关")
@RestController
@RequestMapping("/biz/hospital")
public class BizHospitalController extends BaseController {
    @Resource
    private IBizHospitalService bizHospitalService;


    /**
     * 查询医院列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizHospitalQueryVO queryVO) {
        startPage();
        List<BizHospitalVO> list = bizHospitalService.selectBizHospitalList(queryVO);
        return getDataTable(list);
    }

    /**
     * 查询所有医院列表
     * @return
     */
    @ApiOperation("查询所有医院列表")
    @GetMapping("/getAllHospitalList")
    public AjaxResult getAllHospitalList(){
        BizHospitalQueryVO queryVO = new BizHospitalQueryVO();
        queryVO.setStatus(StatusEnum.active.toString());
        List<BizHospitalVO> list = bizHospitalService.selectBizHospitalList(queryVO);
        return AjaxResult.success(list);
    }

    /**
     * 导出医院列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:hospital:export')")
    @Log(title = "医院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizHospitalQueryVO query) {
        List<BizHospitalVO> list = bizHospitalService.selectBizHospitalList(query);
        ExcelUtil<BizHospitalVO> util = new ExcelUtil<BizHospitalVO>(BizHospitalVO.class);
        util.exportExcel(response, list, "医院数据");
    }

    /**
     * 获取医院详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:hospital:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizHospitalService.selectBizHospitalById(id));
    }

    /**
     * 新增医院
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:hospital:add')")
    @Log(title = "医院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizHospitalFormVO form) {
        return toAjax(bizHospitalService.insertBizHospital(form));
    }

    /**
     * 修改医院
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:hospital:edit')")
    @Log(title = "医院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizHospitalFormVO form) {
        return toAjax(bizHospitalService.updateBizHospital(form));
    }

    /**
     * 删除医院
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:hospital:remove')")
    @Log(title = "医院", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizHospitalService.deleteBizHospitalByIds(ids));
    }

    /**
     * 更改状态医院
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasAnyPermi('biz:hospital:changeStatus,biz:hospital:changeStatusBatch')")
    @Log(title = "医院", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizHospitalService.changeStatus(vo));
    }

    @ApiOperation("查询医院列表")
    @GetMapping("/getHospitalList")
    public AjaxResult getHospitalList(BizHospitalQueryVO queryVO){
        List<BizHospitalVO> list = bizHospitalService.selectBizHospitalList(queryVO);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "查询服务或套餐的医院列表")
    @GetMapping("/getServiceHospitalList")
    public ApiAjaxResult<List<AppServiceHospitalResultVO>> getServiceHospitalList(AppServiceDetailQueryVO queryVO){
        List<AppServiceHospitalResultVO> hospitalList = bizHospitalService.selectAppServiceHospitalList(queryVO);
        return ApiAjaxResult.success(hospitalList);
    }

}
